package org.stone.project.tx.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.stone.project.tx.config.RabbitConfig;
import org.stone.project.tx.model.Message;
import org.stone.project.tx.sysEnum.ReceiveType;

@Service
public class MqMsgSenderImpl implements MqMsgSender{
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private RabbitConfig rabbitConfig;

    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private MqMsgSender mqMsgSender;

    @SneakyThrows
    @Override
    public void sendMsg(ReceiveType receiveType, Message msg) {
        switch (receiveType){
            case USER:
                rabbitTemplate.convertAndSend(rabbitConfig.getTxExchangeUser(),"",msg);
                break;
            case ROLE:
                rabbitTemplate.convertAndSend(rabbitConfig.getTxExchangeRole(),"",msg);
                break;
            case GROUP:
                rabbitTemplate.convertAndSend(rabbitConfig.getTxExchangeGroup(),"",msg);
                break;
            case ALL:
                rabbitTemplate.convertAndSend(rabbitConfig.getTxExchangeAll(),"",msg);
                break;
        }
    }
}
